gdkdevice: Expose tool as property
authorMatthias Clasen <mclasen@redhat.com>
Mon, 11 Apr 2016 15:57:46 +0000 (11:57 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Mon, 11 Apr 2016 16:08:21 +0000 (12:08 -0400)
This may occasionally be useful.

gdk/gdkdevice.c

index 75c6cd2c6ddf18239492f36f4e21726777b1ff30..29c8c8e5df1420209e34c4a5ba86d929bada629b 100644 (file)
@@ -95,6 +95,7 @@ enum {
   PROP_SEAT,
   PROP_NUM_TOUCHES,
   PROP_AXES,
+  PROP_TOOL,
   LAST_PROP
 };
 
@@ -322,6 +323,13 @@ gdk_device_class_init (GdkDeviceClass *klass)
                         GDK_TYPE_AXIS_FLAGS, 0,
                         G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
 
+  device_props[PROP_TOOL] =
+    g_param_spec_object ("tool",
+                         P_("Tool"),
+                         P_("The tool that is currently used with this device"),
+                         GDK_TYPE_DEVICE_TOOL,
+                         G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+
   g_object_class_install_properties (object_class, LAST_PROP, device_props);
 
   /**
@@ -516,6 +524,9 @@ gdk_device_get_property (GObject    *object,
     case PROP_AXES:
       g_value_set_flags (value, device->axis_flags);
       break;
+    case PROP_TOOL:
+      g_value_set_object (value, device->last_tool);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -2034,5 +2045,8 @@ gdk_device_update_tool (GdkDevice     *device,
   g_return_if_fail (gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_MASTER);
 
   if (g_set_object (&device->last_tool, tool))
-    g_signal_emit (device, signals[TOOL_CHANGED], 0, tool);
+    {
+      g_object_notify (G_OBJECT (device), "tool");
+      g_signal_emit (device, signals[TOOL_CHANGED], 0, tool);
+    }
 }